package alipay.openplatform.edu.campus.jiuye.service.services.business;


import alipay.openplatform.edu.campus.jiuye.common.exception.OnlineRuntimeException;
import alipay.openplatform.edu.campus.jiuye.common.utils.CopyVoPo;
import alipay.openplatform.edu.campus.jiuye.common.utils.ObjectUtils;
import alipay.openplatform.edu.campus.jiuye.dao.mappers.business.BllLogoInfoMapper;
import alipay.openplatform.edu.campus.jiuye.model.po.BllLogoInfoPO;
import alipay.openplatform.edu.campus.jiuye.model.vo.BllLogoInfoVO;
import alipay.openplatform.edu.campus.jiuye.service.iservice.business.IBllLogoInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service
public class BllLogoInfoService implements IBllLogoInfoService {


    @Autowired
    private BllLogoInfoMapper bllLogoInfoMapper;

    /**
     * 添加logo
     *
     * @param bllLogoInfoVO
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public void addLogo(BllLogoInfoVO bllLogoInfoVO) throws Exception {

        if (ObjectUtils.hasEmpty(bllLogoInfoVO)) {
            throw new OnlineRuntimeException("PARAM_ERROR", "列表参数传入有空值!");
        }
        String imgUrl = bllLogoInfoVO.getImgUrl();
        String logoUrl = bllLogoInfoVO.getLogoUrl();
        Date startTime = bllLogoInfoVO.getStarttime();
        Date endTime = bllLogoInfoVO.getEndtime();
        Integer createmanid = bllLogoInfoVO.getCreatemanid();
        Boolean isAd = bllLogoInfoVO.getAd();

        BllLogoInfoPO bllLogoInfoPO = new BllLogoInfoPO(logoUrl, imgUrl, startTime, endTime, createmanid, isAd);
        bllLogoInfoMapper.insert(bllLogoInfoPO);


    }

    /**
     * 删除logo
     *
     * @param logoId
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, rollbackFor = Exception.class)
    public void delLogo(Integer logoId) throws Exception {

        if (ObjectUtils.hasEmpty(logoId)) {
            throw new OnlineRuntimeException("PARAM_ERROR", "列表参数传入有空值!");
        }

        bllLogoInfoMapper.deleteByPrimaryKey(logoId);

    }

    /**
     * 获取当前的运营位列表/获取广告位列表-不分页
     *
     * @param isAd
     * @return
     */
    public List<BllLogoInfoVO> queryByIsAd(Boolean isAd) throws Exception {
        BllLogoInfoPO bllLogoInfoPO = new BllLogoInfoPO();
        bllLogoInfoPO.setAd(isAd);
        List<BllLogoInfoPO> bllLogoInfoPOList = new ArrayList<BllLogoInfoPO>();
        bllLogoInfoPOList = bllLogoInfoMapper.selectByisAd(bllLogoInfoPO);
        List<BllLogoInfoVO> bllLogoInfoVOList = new ArrayList<BllLogoInfoVO>();
        if (bllLogoInfoPOList.size() == 0) {
            return null;
        }else {
            bllLogoInfoVOList = CopyVoPo.copyList(bllLogoInfoPOList, BllLogoInfoVO.class);
        }
        return bllLogoInfoVOList;

    }

    /**
     * 获取运营位-后台
     *
     * @return
     */
    public List<BllLogoInfoVO> queryAllAds() throws Exception {

        List<BllLogoInfoPO> bllLogoInfoPOList = bllLogoInfoMapper.selectAllLogoInfo();
        List<BllLogoInfoVO> bllLogoInfoVOList = CopyVoPo.copyList(bllLogoInfoPOList, BllLogoInfoVO.class);
        Map<String, Object> result = new HashMap<String, Object>();
        return bllLogoInfoVOList;
    }

}
